package com.lx.dao;

import com.lx.entity.User;
import org.apache.ibatis.annotations.*;

public interface UserDao {
    /**
     * 登录
     *
     * @param user_name 用户名
     * @param password  密码
     * @return 查询后返回 -> 不等于空 -> 说明查询成功
     */
    @Select("SELECT * FROM user WHERE user_name=#{user_name} AND password=#{password}")
    User login(@Param("user_name") String user_name, @Param("password") String password);

    /**
     * 根据用户名查询用户，验证用户名是否注册
     *
     * @param user_name 用户名
     * @return
     */
    @Select("SELECT * FROM user WHERE user_name=#{user_name}")
    User getIsUser(String user_name);

    /**
     * 根据 id 查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id}")
    User getUserById(int id);

    /**
     * 用户注册
     *
     * @param user_name
     * @param password
     * @param real_name
     * @param birthday
     * @param phone
     * @param address
     * @return
     */
    @Insert("INSERT INTO user VALUES(null,#{user_name},#{password}," +
            "#{real_name},#{birthday},#{phone},#{address})")
    boolean registerUser(
            @Param("user_name") String user_name,
            @Param("password") String password,
            @Param("real_name") String real_name,
            @Param("birthday") String birthday,
            @Param("phone") String phone,
            @Param("address") String address);

    /**
     * 根据id修改用户
     * @param user
     * @return
     */
    @Update("UPDATE user SET user_name=#{user_name},password = #{password},real_name=#{real_name}," +
            "birthday=#{birthday},phone=#{phone},address=#{address} WHERE id=#{id}")
    boolean updateUser(User user);

}
